// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// m [author] rhyme_lph
// E [email]  rhymelph@gmail.com
// c [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/router_gen/router_gen_providers.dart';
import 'package:flutter/material.dart';
import 'package:finance_app/generated/a.dart';

class SplashSecondProvider extends BaseProvider {
  @override
  Future get dataFuture => null;

  PageController controller = PageController();

  List<String> splashImages = [
    A.assetsImagesSplashSplashR4u9,
    A.assetsImagesSplashSplash30iu,
    A.assetsImagesSplashSplash36,
  ];

  List<String> get titleList => [
        S.current.splash_title_1,
        S.current.splash_title_2,
        S.current.splash_title_3,
      ];

  List<String> contentList = [
    S.current.more_than_just_accounting__manage_your_business_on_the_go,
    S.current.snap_photo_to_record__automated_process_for_bookkeeping,
    S.current
        .make_smarter_business_decisions__live_charts_and_reports_at_your_fingertips,
  ];

  int getPageSelectIndex() {
    int selectIndex = controller.initialPage;
    if (controller.hasClients && controller.page != null) {
      selectIndex = controller.page.round();
    }
    return selectIndex;
  }

  void onSkip() {
    RProvider.myProvider.globalMap[ConfigKey.notFirst] = true;
    RProvider.myProvider.updateGlobalMap();
    Routes.navigateTo(RouterGenProviders.loginPage, replace: true);
  }

  void onNext(int selectIndex) {
    if (selectIndex != splashImages.length - 1) {
      controller.nextPage(
          duration: Duration(milliseconds: 500), curve: Curves.linear);
    } else {
      onSkip();
    }
  }
}
